package com.qg.util;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;


@Component
public class ActiveMQUtils {
    //注入消息产生者对象
    @Autowired
     private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * 消息发送方法
     * @param topic 主题
     * @param message 消息的正文
     */
    public void sendMessage(String topic,final Object message){
        Destination destination=new ActiveMQQueue(topic);
        jmsMessagingTemplate.convertAndSend(destination,message);
    }
}
